﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace UI.Forms
{
    public partial class Department : FormBase1
    {
        public Department()
        {
            InitializeComponent();
        }

        private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (e.FocusedRowHandle < 0)
            {

                btn_update.Enabled = btn_delete.Enabled = false;
            }
            else
            {
                btn_update.Enabled = btn_delete.Enabled = true;
            }
        }

        private void Department_Load(object sender, EventArgs e)
        {
            bind();
            
        }

        private void bind()
        {
            gridControl1.DataSource = my.bw.Depratment_Get("DepCode", my.ACID);
        }

        private void btn_new_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Department_N frm = new Department_N();
            frm.FatherRefresh = bind;
            frm.ShowDialog(this);
        }

        private void btn_update_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SVC.client.Depratment cur = null;
            try
            {
                cur = gridView1.GetRow(gridView1.FocusedRowHandle) as SVC.client.Depratment;
            }
            catch { }
            if (cur != null)
            {
                Department_U frm = new Department_U(cur);
                frm.FatherRefresh = bind;
                frm.ShowDialog(this);
            }
        }

        private void btn_delete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SVC.client.Depratment cur = null;
            try
            {
                cur = gridView1.GetRow(gridView1.FocusedRowHandle) as SVC.client.Depratment;
            }
            catch { }
            if (cur != null)
            {
                if (DialogResult.No == XtraMessageBox.Show("你确定要删除当前焦点行数据？", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button2))
                {
                    return;
                }
                string r = my.bw.DepratmentByDepCode_Delete(cur.DepCode, my.ACID);
                if (string.IsNullOrWhiteSpace(r))
                {
                    bind();
                }
                else
                {
                    Comm.ShowErorr(r);
                }
            }
        }
    }
}